package com.thrc.borrow.service;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.thrc.borrow.dao.UserDao;
import com.thrc.borrow.entity.User;
import com.thrc.borrow.vo.UserVo;

@Service
public class UserService implements BaseService<User, UserVo> {

	@Autowired
	private UserDao userDao;

	@Override
	public UserVo selectById(User t) {
		return userDao.selectById(t);
	}

	@Override
	public List<UserVo> selectAll(User t) {
		return userDao.selectAll(t);
	}

	@Override
	public int selectCount(User t) {
		return userDao.selectCount(t);
	}

	@Override
	public List<UserVo> selectByPage(User t) {
		t.setStartRow(t.getPageIndex(), t.getPageSize());
		return userDao.selectByPage(t);
	}

	@Override
	public void update(User t) {
		userDao.update(t);
	}

	public void login(User t) {
		userDao.update(t);
	}

	public void updatePwd(User t) {
		userDao.update(t);
	}

	@Override
	public void delete(User t) {
		userDao.delete(t);
	}

	@Override
	public void insert(User t) {
		userDao.insert(t);
	}

	public UserVo selectByPhone(User t) {
		return userDao.selectByPhone(t);
	}

	public String getRoleListById(User t) {
		List<String> list = userDao.getRoleListById(t);
		if (list == null || list.size() == 0)
			return "";
		StringBuilder retSb = new StringBuilder();
		for (String id : list) {
			retSb.append(id).append(",");
		}
		if (retSb.length() > 0)
			return retSb.substring(0, retSb.length() - 1);

		return retSb.toString();
	}

	public User checkLogin(String phone, String password) {
		return userDao.checkLogin(phone, password);
	}

}
